package qc.module.cms.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.cms.dto.swipper.EditFlagDto;
import qc.module.cms.dto.swipper.SwipperDto;
import qc.module.cms.dto.swipper.SwipperQueryConditionDto;
import qc.module.cms.service.CategorySwipperService;

import java.util.List;

/**
 * SwipperController
 *
 * @author QuCheng Tech
 * @create 2023/5/26
 */
@RestController
@RequestMapping("/swipper")
public class SwipperController {

    private CategorySwipperService service;

    @Autowired
    public void setService(CategorySwipperService service) {
        this.service = service;
    }

    //是否为逻辑删除，为true表示逻辑删除--修改记录标记，为false表示物理删除--从数据库表中删除记录
    private static final boolean isLogicDelete = false;

    /**
     * 获取指定栏目下的轮播图
     *
     * @param condition: 查询条件
     * @return List<SwipperDisplayDto> 轮播图信息集合
     * @author QcCheng Tech
     * @date 2023/7/17
     */
    @RequestMapping(value = "/category", method = {RequestMethod.POST, RequestMethod.GET})
    public List<SwipperDto> getByParam(@RequestBody SwipperQueryConditionDto condition) throws QCPromptException {
        return service.getCategoryAllSwippers(condition.getCid());
    }

    /**
     * 新增轮播图
     *
     * @param dto: 新增轮播图信息
     * @return String 成功返回true
     * @author QcCheng Tech
     * @date 2023/7/17
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public String add(@RequestBody SwipperDto dto) {
        return service.add(dto);
    }

    /**
     * 修改轮播图信息
     *
     * @param dto:修改条件
     * @return String 修改成功返回null
     * @author QcCheng Tech
     * @date 2023/7/17
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody SwipperDto dto) {
        return service.update(dto);
    }

    /**
     * 删除轮播图，isLogicDelete：是否为逻辑删除，为true表示逻辑删除--修改记录标记，为false表示物理删除--从数据库表中删除记录
     *
     * @param id 轮播图id
     * @return 成功放回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/15
     */
    @RequestMapping(value = "/delete/{id}", method = {RequestMethod.DELETE})
    public String deleteByPath(@PathVariable(required = true) int id) {
        return service.delete(id, isLogicDelete);
    }

    /**
     * 删除轮播图，isLogicDelete：是否为逻辑删除，为true表示逻辑删除--修改记录标记，为false表示物理删除--从数据库表中删除记录
     *
     * @param id 轮播图id
     * @return 成功放回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/15
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE})
    public String deleteByParam(@RequestParam int id) {
        return service.delete(id, isLogicDelete);
    }

    /**
     * 启用或禁用轮播图，修改轮播图状态值
     *
     * @param dto: 设置信息
     * @return String 成功返回null,失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/23
     */
    @RequestMapping(value = "/editflag", method = {RequestMethod.POST})
    public String enableByParam(@RequestBody EditFlagDto dto) {
        return service.editFlag(dto);
    }
}